/**
 * Collaborative Story Development Web Application (CSDApp) 
 * Copyright Anton Strack 2014
 *
 * This file is part of Collaborative Story Development Application (CSDApp).
 *
 * CSDApp is free software: you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or any later version.
 *
 * CSDApp is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * CSDApp. If not, see <http://www.gnu.org/licenses/>.
 *
 */
package csdwa;

import java.sql.Connection;

/**
 * This class provides access to the dao classes and also a method to select a
 * dao class according to the resource type id.
 *
 * @author Anton Strack
 */
public class DaoFactory {

    private Connection conn;

    public DaoFactory(Connection conn) {
        this.conn = conn;
    }

    /**
     * This method provides a means to select a dao according to the resource.
     *
     * @param resourceTypeId the id of the resource the dao is for.
     * @return the proper dao for the resource or null if none exist.
     */
    public CsdwaDao getDao(int resourceTypeId) {

        CsdwaDao dao;
        switch (resourceTypeId) {
            case 3: // plot
            {
                dao = makePlotDao(conn);
                break;
            }
            case 4: // character
            {
                dao = makeCharacterDao(conn);
                break;
            }
            case 5: // dialog
            {
                dao = makeDialogDao(conn);
                break;
            }
            case 6: // location
            {
                dao = makeLocationDao(conn);
                break;
            }
            case 7: // comment
            {
                dao = makeCommentDao(conn);
                break;
            }
            case 8: // category
            {
                dao = makeCategoryDao(conn);
                break;
            }
            case 9: // relationship
            {
                dao = makeRelationshipDao(conn);
                break;
            }

            case 16: // task
            {

                dao = makeTaskDao(conn);
                break;
            }
            case 17: // notification
            {

                dao = makeNotificationDao(conn);
                break;
            }

            case 20: // postHistory
            {
                dao = makePostHistoryDao(conn);
                break;
            }
            default: {
                dao = null;
                break;
            }
        }
        return dao;
    }

    /**
     * Make a plot dao
     *
     * @param conn connection that the controller can use
     * @return the dao
     */
    public static PlotDao makePlotDao(Connection conn) {
        return new PlotDao(conn);
    }

    /**
     * Make a character dao
     *
     * @param conn connection that the controller can use
     * @return the dao
     */
    public static CharacterDao makeCharacterDao(Connection conn) {
        return new CharacterDao(conn);
    }

    /**
     * Make a dialog dao
     *
     * @param conn connection that the controller can use
     * @return the dao
     */
    public static DialogDao makeDialogDao(Connection conn) {
        return new DialogDao(conn);
    }
//

    /**
     * Make a location dao
     *
     * @param conn connection that the controller can use
     * @return the dao
     */
    public static LocationDao makeLocationDao(Connection conn) {
        return new LocationDao(conn);
    }

    /**
     * Make a relationship dao
     *
     * @param conn connection that the controller can use
     * @return the dao
     */
    public static RelationshipDao makeRelationshipDao(Connection conn) {
        return new RelationshipDao(conn);
    }

    /**
     * Make a comment dao
     *
     * @param conn connection that the controller can use
     * @return the dao
     */
    public static CommentDao makeCommentDao(Connection conn) {
        return new CommentDao(conn);
    }

    /**
     * Make a post history dao
     *
     * @param conn connection that the dao can use
     * @return the dao
     */
    public static UserHistoryDao makePostHistoryDao(Connection conn) {
        return new UserHistoryDao(conn);
    }

    /**
     * Make a notification dao
     *
     * @param conn connection that the dao can use
     * @return the dao
     */
    public static NotificationDao makeNotificationDao(Connection conn) {
        return new NotificationDao(conn);
    }
//

    /**
     * Make a task dao
     *
     * @param conn connection that the dao can use
     * @return the dao
     */
    public static TaskDao makeTaskDao(Connection conn) {
        return new TaskDao(conn);
    }

    /**
     * Make a category dao
     *
     * @param conn connection that the dao can use
     * @return the dao
     */
    public static CategoryDao makeCategoryDao(Connection conn) {
        return new CategoryDao(conn);
    }
}
